<template>
	<view class="edit">
		<form action="" @submit="OnSubmit">
			<view class="item">
				<input v-model="formValue.title" name="title" placeholder="请输入标题" type="text">
			</view>
			<view class="item">
				<input v-model="formValue.author" name="author" placeholder="请输入作者" type="text">
			</view>
			<view class="item">
				<textarea v-model="formValue.content" name="content" placeholder="请输入详细内容"></textarea> 
			</view>
			<view class="item">
				<button type="primary" form-type="submit" :disabled="isDisable(formValue)">提交</button>
				<button form-type="reset">重置</button>
			</view>
		</form>
		
	</view>
</template>

<script>
	let id;
	export default {
		data() {
			return {
				formValue:{
					title:"",
					author:"",
					content:""
				}
			};
		},
		onLoad(e) {
			id=e.id;
			this.getDetailById(id)
		},
		methods:{
			// 判断输入是否为空
			isDisable(res){
				console.log(res)
				for(let i in res){
					if(!res[i]){ // 没值——>true(禁用)（有一个没值都返回true）
						return true;
					}
				}
			},
			getDetailById(id){
				uniCloud.callFunction({
					name:"art_get_row",
					data:{
						id
					}
				}).then((res)=>{
					this.formValue= res.result.data[0];
					console.log(this.formValue)
				})
			},
			OnSubmit(e){
				uniCloud.callFunction({
					name:"art_update_row",
					data:{
						detail:this.formValue
					}
				}).then(e=>{
					console.log(e);
					
					uni.showToast({
						title:"修改成功"
					})
					
					setTimeout(()=>{ 
						uni.navigateBack() // 返回上一页，必须得通过导航跳转
					},800) // 设置延时定时器
				})
			}
		}
	}
</script>

<style lang="scss">
.edit{
	padding: 30rpx;
	.item{
		padding-bottom: 20rpx;
		input,textarea{
			border: 1rpx solid #eee;
			height: 80rpx;
			padding: 0 20rpx;
		}
		textarea{
			height: 200rpx;
			width: 100%;
			box-sizing: border-box;
		}
	}
}
</style>
